// var base_url;
var skins_admin;
var upload_path;
var oTable;
var count_photo=0;
upload_path = base_url + 'assets/uploads';
skins_admin = base_url + 'assets/admin';

function load_view(url,param){
    $('.content-box').load(url,param);
}
/* *********************************************************************
 * Notifications
 * *********************************************************************/
function InitNotifications (status,content) {
    $('.notification .close').click(function () {
        $(this).parent().fadeOut(1000, function() {
            $(this).find('p').fixClearType ();
        });
        return false;
    });
    $('.notification').addClass('note-'+status);
    $('.notification p').html(content);
    $('.notification').show('slow');
}
function InitWYSIWYG () {
    $('.jwysiwyg').wysiwyg();
}

$(document).ready(function(){
    InitMenuEffects();
})

/* *********************************************************************
 * Main Menu
 * *********************************************************************/
function InitMenuEffects () {
    var fluid = {
        Toggle : function(){
            var default_hide = {
                "grid": true
            };
            $.each(
                ["navcat", "commentsnav", "userssnav", "imagesnav"],
                function() {
                    var el = $("#" + (this == 'accordon' ? 'accordion-block' : this) );
                    if (default_hide[this]) {
                        el.hide();
                        $("[id='toggle-"+this+"']").addClass("hidden")
                    }
                    $("[id='toggle-"+this+"']")
                    .bind("click", function(e) {
                        if ($(this).hasClass('hidden')){
                            $(this).removeClass('hidden').addClass('visible');
                            el.slideDown();
                        } else {
                            $(this).removeClass('visible').addClass('hidden');
                            el.slideUp();
                        }
                        e.preventDefault();
                    });
                }
                );
        }
    }
    if($("[id^='toggle']").length){
        fluid.Toggle();
    }
}
/* *********************************************************************
 * Content Boxes
 * *********************************************************************/
function InitCheckAll () {
    /* Checkboxes */
    $('.content-box .select-all').click(function () {
        if ($(this).is(':checked'))
            $(this).parent().parent().parent().parent().find(':checkbox').attr('checked', true);
        else
            $(this).parent().parent().parent().parent().find(':checkbox').attr('checked', false);
    });
}
function InitTabs(){
    /* Tabs */
    $('.content-box .tabs').idTabs();
}

/* *********************************************************************
 * Fancybox
 * *********************************************************************/
function InitFancybox () {
    $('.modal-link').fancybox({
        'modal' 				: false,
        'hideOnOverlayClick' 	: 'true',
        'hideOnContentClick' 	: 'true',
        'enableEscapeButton' 	: true,
        'showCloseButton' 	: true
    });

    $("a[href$='gif']").fancybox();
    $("a[href$='jpg']").fancybox();
    $("a[href$='png']").fancybox();
}

/* *********************************************************************
 * Data Tables
 * *********************************************************************/
function InitTables (col_alt) {
    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
        "alt-string-pre": function ( a ) {
            return a.match(/alt="(.*?)"/)[1].toLowerCase();
        },

        "alt-string-asc": function( a, b ) {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },

        "alt-string-desc": function(a,b) {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
        }
    } );
    oTable = $('.datatable').dataTable({
        "bSort": false,
        'bLengthChange': false,
        'bPaginate': true,
        'sPaginationType': 'full_numbers',
        'iDisplayLength': 10,
        'bInfo': true,
        "bFilter": false,
        "aoColumnDefs": [
        {
            "sType": 'alt-string',
            "aTargets": [ col_alt ]
        }
        ],
        'oLanguage':
        {
            // 'sSearch': 'Search all columns:',
            'oPaginate':
            {
                'sNext': '&gt;',
                'sLast': '&gt;&gt;',
                'sFirst': '&lt;&lt;',
                'sPrevious': '&lt;'
            }
        }
    });
}

jQuery.fn.fixClearType = function(){
    return this.each(function(){
        if( !!(typeof this.style.filter  && this.style.removeAttribute))
            this.style.removeAttribute("filter");
    })

}

/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();

    for ( var i=0 ; i<aTrs.length ; i++ )
    {
        if ( $(aTrs[i]).hasClass('row_selected') )
        {
            aReturn.push( aTrs[i] );
        }
    }
    return aReturn;
}

function confirm_del(){
    return confirm("Are you sure delete this item ?")
}

function confirm_update(){
    return confirm("Current data will lost.Are you sure update ?")
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}

